﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;


namespace VAdvantage.Grids
{
    public class DataGridImageColumn:DataGridBoundColumn
    {
        ImageSource _imgSource = null;

        Image image = null;


        public event RoutedEventHandler Click = null;


        public ImageSource Image
        {
            get
            {
                return _imgSource;
            }
            set
            {
                _imgSource = value;
//                backgroundBrush.ImageSource = _imgSource;
            }

        }
        protected override FrameworkElement GenerateEditingElement(DataGridCell cell, object dataItem)
        {
            return (FrameworkElement)cell.Content;
        }

        protected override FrameworkElement GenerateElement(DataGridCell cell, object dataItem)
        {
            if (cell.Content is Button)
            {
                return (Button)cell.Content;
            }

            Button btn = new Button();
            btn.Margin = new Thickness(1);
            btn.BorderThickness = new Thickness(0);
            btn.Width = 20;
            btn.Height = 20;
            image = new Image() { Source = _imgSource, Stretch=Stretch.Fill};
            //btn.Background =  backgroundBrush;
            btn.Content = image;
            btn.Click += new RoutedEventHandler(btn_Click);
            return btn;
        }

        void btn_Click(object sender, RoutedEventArgs e)
        {
            if (Click != null)
            {
                Click(this, e);
            }
        }

        protected override object PrepareCellForEdit(FrameworkElement editingElement, RoutedEventArgs editingEventArgs)
        {
            //throw new NotImplementedException();
            return editingElement;
        }

       
    }
}
